package com.ChenYaRou.www.utils;

import javax.servlet.*;
import java.io.IOException;

/**
 * @ClassName Filter
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 23:50
 * @Version 1.0
 **/
public class Filter implements javax.servlet.Filter{
    @Override
    public void init(FilterConfig filterConfig) {

    }

    /**
     * 对resp req设置编码
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text/html;UTF-8");

        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
